import pandas as pd
from datetime import datetime, timedelta, time
import numpy as np

df = pd.DataFrame({ 'prod_code': ['MK', 'LK', 'NH', 'O0'],
'delivery_date_chr': ['20240109', '20240429', '20240527', '20240825']
})


date_chr = "20240109"
date_dt = pd.to_datetime(date_chr, format='%Y%m%d')
print(date_dt.weekday())  # 直接调用 weekday() 方法

df['delivery_date'] = pd.to_datetime(df['delivery_date_chr'], format='%Y%m%d')
def cal_weekday(x):
    date_chr = x.delivery_date
    date_dt = pd.to_datetime(date_chr, format='%Y%m%d')
    rst = (date_dt.weekday())
    return rst
df['weekday'] = df.apply(lambda x: cal_weekday(x), axis=1)

df['delivery_date'] = pd.to_datetime(df['delivery_date_chr'], format='%Y%m%d')
print(df['delivery_date'].dtype)
df['weekday'] = df['delivery_date'].weekday()




